{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "7361740c",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.append(\"Alex\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "57117946",
   "metadata": {},
   "source": [
    "# 列表的私有方法\n",
    "增加append()增加在list的末尾"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "aad2462d",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['Mike', 'Marry', 'Jan', 'Jack', 'Alex', 'zhichao']"
      ]
     },
     "execution_count": 7,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.append(\"Alex\")\n",
    "names.append(\"zhichao\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b061df4e",
   "metadata": {},
   "source": [
    "列表里面可以放重复出现的值，需要唯一一个值时列表不太合适"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "0554ed8d",
   "metadata": {},
   "source": [
    "插入insert（）可以指定位置增加元素"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "709cd9f1",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['youge', 'Mike', 'Marry', 'Jan', 'Jack', 'Alex', 'zhichao']"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.append(\"Alex\")\n",
    "names.append(\"zhichao\")\n",
    "names.insert(0,\"youge\")\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "7c8d55cf",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['youge', 'Mike', 'youge', 'Marry', 'Jan', 'Jack', 'Alex', 'zhichao']"
      ]
     },
     "execution_count": 15,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.append(\"Alex\")\n",
    "names.append(\"zhichao\")\n",
    "names.insert(0,\"youge\")\n",
    "names.insert(2,\"youge\")\n",
    "names"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8c498f56",
   "metadata": {},
   "source": [
    "删除remove 和 pop\n",
    "remove()一般情况下 使用remove先用in做判断"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "8b414c68",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "['youge', 'Mike', 'youge', 'Marry', 'Jan', 'Jack', 'Alex']"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.append(\"Alex\")\n",
    "names.append(\"zhichao\")\n",
    "names.insert(0,\"youge\")\n",
    "names.insert(2,\"youge\")\n",
    "names.remove(\"zhichao\")\n",
    "names"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "6d9bba17",
   "metadata": {},
   "outputs": [],
   "source": [
    "names.insert(1,'youge')"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "43f0d9f7",
   "metadata": {},
   "source": [
    "len()查看list长度"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "c3cd11a0",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "names的长度/names的列表元素的个数: 4\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "print(\"names的长度/names的列表元素的个数:\", len(names))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "b207e2e0",
   "metadata": {},
   "source": [
    "index索引 查看该元素如1001在stu_id中第一个出现的位置索引"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "950d570f",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0\n"
     ]
    }
   ],
   "source": [
    "stu_id =[1001,1002,1003,1004,1008,1001,1009,1020,1001]\n",
    "print(stu_id.index(1001))"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "f371eacd",
   "metadata": {},
   "source": [
    "clear()清除所有数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "id": "a9c9eaaf",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "清除names列表后的值： []\n"
     ]
    }
   ],
   "source": [
    "names = [\"Mike\",\"Marry\",\"Jan\",\"Jack\"]\n",
    "names.clear()\n",
    "print (\"清除names列表后的值：\",names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "a468ec26",
   "metadata": {},
   "source": [
    "count()查看列表元素出现的个数，（简单应用）统计分数出现的次数"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "ab7417b7",
   "metadata": {},
   "outputs": [],
   "source": [
    "stu_id =[1001,1002,1003,1004,1008,1001,1009,1020,1001]\n",
    "print(\"count方法的结果：\"，stu_id.count(1001))\n",
    "print(name)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "719f7cb4",
   "metadata": {},
   "source": [
    "extend()是给指定的list进行扩充"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "id": "605c4428",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "[1001, 1003, 1004, 1008, 1001, 1009, 1020, 1001]\n"
     ]
    }
   ],
   "source": [
    "names.extend(stu_id)\n",
    "print(names)"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "408e020f",
   "metadata": {},
   "source": [
    "## list方法的总结，list的切片的总结（作业）"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "646d75f6",
   "metadata": {},
   "source": [
    "copy()很重要\n",
    "思考，赋值是真正的复制吗？赋值（=）<=> copy?"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "e9fe5c84",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [1001, 1002, 1003, 1004, 1008, 1001, 1009, 1020, 1001] \n",
      " stu_id_matedata: [1001, 1002, 1003, 1004, 1008, 1001, 1009, 1020, 1001]\n"
     ]
    }
   ],
   "source": [
    "stu_id =[1001,1002,1003,1004,1008,1001,1009,1020,1001]\n",
    "stu_id_matedata = stu_id\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "26912268",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "stu_id: [1001, 1002, 1003, 1004, 1008, 1001, 1009, 1020, 1001] \n",
      " stu_id_matedata: [1001, 1002, 1003, 1004, 1008, 1001, 1009, 1020, 1001]\n",
      "stu_id: [1001, 1003, 1004, 1008, 1001, 1009, 1020, 1001] \n",
      " stu_id_matedata: [1001, 1003, 1004, 1008, 1001, 1009, 1020, 1001]\n"
     ]
    }
   ],
   "source": [
    "stu_id =[1001,1002,1003,1004,1008,1001,1009,1020,1001]\n",
    "stu_id_matedata = stu_id\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)\n",
    "stu_id.pop(1)\n",
    "print(\"stu_id:\",stu_id,'\\n','stu_id_matedata:',stu_id_matedata)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "id": "a6ab3c49",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "0 1001\n",
      "5 1001\n",
      "8 1001\n",
      "我们想要删除pop（）的值： [0, 5, 8]\n"
     ]
    }
   ],
   "source": [
    "stu_id =[1001,1002,1003,1004,1008,1001,1009,1020,1001]\n",
    "\n",
    "#for i in stu_id:\n",
    "        #循环遍历stu_id的所有内容\n",
    "        # if i == 1001:\n",
    "                #判断如果元素为1001的时候，怎么取出索引呢？\n",
    "           # print(i)\n",
    "#因为list其实不仅有values值，还有index索引，但for循环主要循环遍历其值，因此，有了枚举的方法，同时遍历两遍    \n",
    "#enumerate()\n",
    "pop_values_list = []\n",
    "for index,item in enumerate(stu_id):\n",
    "    if item == 1001:\n",
    "        print(index,item)\n",
    "        pop_values_list.append(index)\n",
    "print(\"我们想要删除pop（）的值：\",pop_values_list)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "71d409fa",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Help on int object:\n",
      "\n",
      "class int(object)\n",
      " |  int([x]) -> integer\n",
      " |  int(x, base=10) -> integer\n",
      " |  \n",
      " |  Convert a number or string to an integer, or return 0 if no arguments\n",
      " |  are given.  If x is a number, return x.__int__().  For floating point\n",
      " |  numbers, this truncates towards zero.\n",
      " |  \n",
      " |  If x is not a number or if base is given, then x must be a string,\n",
      " |  bytes, or bytearray instance representing an integer literal in the\n",
      " |  given base.  The literal can be preceded by '+' or '-' and be surrounded\n",
      " |  by whitespace.  The base defaults to 10.  Valid bases are 0 and 2-36.\n",
      " |  Base 0 means to interpret the base from the string as an integer literal.\n",
      " |  >>> int('0b100', base=0)\n",
      " |  4\n",
      " |  \n",
      " |  Built-in subclasses:\n",
      " |      bool\n",
      " |  \n",
      " |  Methods defined here:\n",
      " |  \n",
      " |  __abs__(self, /)\n",
      " |      abs(self)\n",
      " |  \n",
      " |  __add__(self, value, /)\n",
      " |      Return self+value.\n",
      " |  \n",
      " |  __and__(self, value, /)\n",
      " |      Return self&value.\n",
      " |  \n",
      " |  __bool__(self, /)\n",
      " |      self != 0\n",
      " |  \n",
      " |  __ceil__(...)\n",
      " |      Ceiling of an Integral returns itself.\n",
      " |  \n",
      " |  __divmod__(self, value, /)\n",
      " |      Return divmod(self, value).\n",
      " |  \n",
      " |  __eq__(self, value, /)\n",
      " |      Return self==value.\n",
      " |  \n",
      " |  __float__(self, /)\n",
      " |      float(self)\n",
      " |  \n",
      " |  __floor__(...)\n",
      " |      Flooring an Integral returns itself.\n",
      " |  \n",
      " |  __floordiv__(self, value, /)\n",
      " |      Return self//value.\n",
      " |  \n",
      " |  __format__(self, format_spec, /)\n",
      " |      Default object formatter.\n",
      " |  \n",
      " |  __ge__(self, value, /)\n",
      " |      Return self>=value.\n",
      " |  \n",
      " |  __getattribute__(self, name, /)\n",
      " |      Return getattr(self, name).\n",
      " |  \n",
      " |  __getnewargs__(self, /)\n",
      " |  \n",
      " |  __gt__(self, value, /)\n",
      " |      Return self>value.\n",
      " |  \n",
      " |  __hash__(self, /)\n",
      " |      Return hash(self).\n",
      " |  \n",
      " |  __index__(self, /)\n",
      " |      Return self converted to an integer, if self is suitable for use as an index into a list.\n",
      " |  \n",
      " |  __int__(self, /)\n",
      " |      int(self)\n",
      " |  \n",
      " |  __invert__(self, /)\n",
      " |      ~self\n",
      " |  \n",
      " |  __le__(self, value, /)\n",
      " |      Return self<=value.\n",
      " |  \n",
      " |  __lshift__(self, value, /)\n",
      " |      Return self<<value.\n",
      " |  \n",
      " |  __lt__(self, value, /)\n",
      " |      Return self<value.\n",
      " |  \n",
      " |  __mod__(self, value, /)\n",
      " |      Return self%value.\n",
      " |  \n",
      " |  __mul__(self, value, /)\n",
      " |      Return self*value.\n",
      " |  \n",
      " |  __ne__(self, value, /)\n",
      " |      Return self!=value.\n",
      " |  \n",
      " |  __neg__(self, /)\n",
      " |      -self\n",
      " |  \n",
      " |  __or__(self, value, /)\n",
      " |      Return self|value.\n",
      " |  \n",
      " |  __pos__(self, /)\n",
      " |      +self\n",
      " |  \n",
      " |  __pow__(self, value, mod=None, /)\n",
      " |      Return pow(self, value, mod).\n",
      " |  \n",
      " |  __radd__(self, value, /)\n",
      " |      Return value+self.\n",
      " |  \n",
      " |  __rand__(self, value, /)\n",
      " |      Return value&self.\n",
      " |  \n",
      " |  __rdivmod__(self, value, /)\n",
      " |      Return divmod(value, self).\n",
      " |  \n",
      " |  __repr__(self, /)\n",
      " |      Return repr(self).\n",
      " |  \n",
      " |  __rfloordiv__(self, value, /)\n",
      " |      Return value//self.\n",
      " |  \n",
      " |  __rlshift__(self, value, /)\n",
      " |      Return value<<self.\n",
      " |  \n",
      " |  __rmod__(self, value, /)\n",
      " |      Return value%self.\n",
      " |  \n",
      " |  __rmul__(self, value, /)\n",
      " |      Return value*self.\n",
      " |  \n",
      " |  __ror__(self, value, /)\n",
      " |      Return value|self.\n",
      " |  \n",
      " |  __round__(...)\n",
      " |      Rounding an Integral returns itself.\n",
      " |      Rounding with an ndigits argument also returns an integer.\n",
      " |  \n",
      " |  __rpow__(self, value, mod=None, /)\n",
      " |      Return pow(value, self, mod).\n",
      " |  \n",
      " |  __rrshift__(self, value, /)\n",
      " |      Return value>>self.\n",
      " |  \n",
      " |  __rshift__(self, value, /)\n",
      " |      Return self>>value.\n",
      " |  \n",
      " |  __rsub__(self, value, /)\n",
      " |      Return value-self.\n",
      " |  \n",
      " |  __rtruediv__(self, value, /)\n",
      " |      Return value/self.\n",
      " |  \n",
      " |  __rxor__(self, value, /)\n",
      " |      Return value^self.\n",
      " |  \n",
      " |  __sizeof__(self, /)\n",
      " |      Returns size in memory, in bytes.\n",
      " |  \n",
      " |  __sub__(self, value, /)\n",
      " |      Return self-value.\n",
      " |  \n",
      " |  __truediv__(self, value, /)\n",
      " |      Return self/value.\n",
      " |  \n",
      " |  __trunc__(...)\n",
      " |      Truncating an Integral returns itself.\n",
      " |  \n",
      " |  __xor__(self, value, /)\n",
      " |      Return self^value.\n",
      " |  \n",
      " |  as_integer_ratio(self, /)\n",
      " |      Return integer ratio.\n",
      " |      \n",
      " |      Return a pair of integers, whose ratio is exactly equal to the original int\n",
      " |      and with a positive denominator.\n",
      " |      \n",
      " |      >>> (10).as_integer_ratio()\n",
      " |      (10, 1)\n",
      " |      >>> (-10).as_integer_ratio()\n",
      " |      (-10, 1)\n",
      " |      >>> (0).as_integer_ratio()\n",
      " |      (0, 1)\n",
      " |  \n",
      " |  bit_length(self, /)\n",
      " |      Number of bits necessary to represent self in binary.\n",
      " |      \n",
      " |      >>> bin(37)\n",
      " |      '0b100101'\n",
      " |      >>> (37).bit_length()\n",
      " |      6\n",
      " |  \n",
      " |  conjugate(...)\n",
      " |      Returns self, the complex conjugate of any int.\n",
      " |  \n",
      " |  to_bytes(self, /, length, byteorder, *, signed=False)\n",
      " |      Return an array of bytes representing an integer.\n",
      " |      \n",
      " |      length\n",
      " |        Length of bytes object to use.  An OverflowError is raised if the\n",
      " |        integer is not representable with the given number of bytes.\n",
      " |      byteorder\n",
      " |        The byte order used to represent the integer.  If byteorder is 'big',\n",
      " |        the most significant byte is at the beginning of the byte array.  If\n",
      " |        byteorder is 'little', the most significant byte is at the end of the\n",
      " |        byte array.  To request the native byte order of the host system, use\n",
      " |        `sys.byteorder' as the byte order value.\n",
      " |      signed\n",
      " |        Determines whether two's complement is used to represent the integer.\n",
      " |        If signed is False and a negative integer is given, an OverflowError\n",
      " |        is raised.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Class methods defined here:\n",
      " |  \n",
      " |  from_bytes(bytes, byteorder, *, signed=False) from builtins.type\n",
      " |      Return the integer represented by the given array of bytes.\n",
      " |      \n",
      " |      bytes\n",
      " |        Holds the array of bytes to convert.  The argument must either\n",
      " |        support the buffer protocol or be an iterable object producing bytes.\n",
      " |        Bytes and bytearray are examples of built-in objects that support the\n",
      " |        buffer protocol.\n",
      " |      byteorder\n",
      " |        The byte order used to represent the integer.  If byteorder is 'big',\n",
      " |        the most significant byte is at the beginning of the byte array.  If\n",
      " |        byteorder is 'little', the most significant byte is at the end of the\n",
      " |        byte array.  To request the native byte order of the host system, use\n",
      " |        `sys.byteorder' as the byte order value.\n",
      " |      signed\n",
      " |        Indicates whether two's complement is used to represent the integer.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Static methods defined here:\n",
      " |  \n",
      " |  __new__(*args, **kwargs) from builtins.type\n",
      " |      Create and return a new object.  See help(type) for accurate signature.\n",
      " |  \n",
      " |  ----------------------------------------------------------------------\n",
      " |  Data descriptors defined here:\n",
      " |  \n",
      " |  denominator\n",
      " |      the denominator of a rational number in lowest terms\n",
      " |  \n",
      " |  imag\n",
      " |      the imaginary part of a complex number\n",
      " |  \n",
      " |  numerator\n",
      " |      the numerator of a rational number in lowest terms\n",
      " |  \n",
      " |  real\n",
      " |      the real part of a complex number\n",
      "\n"
     ]
    }
   ],
   "source": [
    "help(item)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "c2e565ae",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  },
  "toc": {
   "base_numbering": 1,
   "nav_menu": {},
   "number_sections": true,
   "sideBar": true,
   "skip_h1_title": false,
   "title_cell": "Table of Contents",
   "title_sidebar": "Contents",
   "toc_cell": false,
   "toc_position": {},
   "toc_section_display": true,
   "toc_window_display": false
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
